﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InSys.Documents
{
    public partial class FormSelectKindDocument : Form
    {
        private int result = 0;
        public int KindDocument { 
            get
            { 
                return result; 
            }
             set 
             { 
                 result = value;
                 listBoxKindDocument.SelectedItem = result;
                 listBoxKindDocument.Invalidate();
             } 
        }
        private MapTestLinqDataContext db = new MapTestLinqDataContext();
        public FormSelectKindDocument()
        {
            InitializeComponent();
        }

        private void FormSelectKindDocument_Load(object sender, EventArgs e)
        {
            db.ObjectTrackingEnabled = false;
            bindingSourceKindDocument.DataSource = db.kindDocument;
            listBoxKindDocument.SelectedValue = result;
            listBoxKindDocument.Invalidate();
            result = 0;
        }

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            getSelectResult();
            DialogResult = DialogResult.OK;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void listBoxKindDocument_DoubleClick(object sender, EventArgs e)
        {
            getSelectResult();
            DialogResult = DialogResult.OK;
        }

        private void getSelectResult()
        {
            result = listBoxKindDocument.SelectedValue is int ? (int)listBoxKindDocument.SelectedValue : 0;
        }
    }
}
